package main;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import JaCoP.constraints.XneqY;
import JaCoP.core.Store;
import JaCoP.core.IntVar;

import generated.FeatureType;
import generated.FeatureType.MandatoryComposition;
import generated.FeatureType.OptionalComposition;
import generated.Productline;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			JAXBContext c = JAXBContext.newInstance(new Class[] {Productline.class});
			Unmarshaller um = c.createUnmarshaller();
			Productline pl = (Productline) um.unmarshal(new File("QPL.xml"));
			
			//JaCoP aanroepen
			Map<String, IntVar> map = new HashMap<String, IntVar>();
			
			//new XneqY();
			Store store = new Store();
			
			//Stap 1: Haal alle features op
			for(FeatureType ft:pl.getPerspective().get(0).getFeature()){
				map.put(ft.getId(), new IntVar(store, ft.getName(), 1, 1));
				for(Object o : ft.getContent()){
					if(o instanceof JAXBElement){
						JAXBElement el = (JAXBElement) o;
						if(el.getValue() instanceof OptionalComposition){
							OptionalComposition oc = (OptionalComposition) el.getValue();
							for(FeatureType subFT : oc.getFeature()){
								map.put(subFT.getId(), new IntVar(store, subFT.getName(), 1, 1));
							}
						} else if (el.getValue() instanceof MandatoryComposition){
							MandatoryComposition mc = (MandatoryComposition) el.getValue();
							for(FeatureType subFT : mc.getFeature()){
								map.put(subFT.getId(), new IntVar(store, subFT.getName(), 1, 1));
							}
						}
					}
				}
			}
			
			//Stap 2: loop nog eens over tree en maak de nodige restricties aan
			
			for(Entry<String, IntVar> entry : map.entrySet()){
				System.out.println(entry.getKey() + " " + entry.getValue().id());
			}
			
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

}
